package tongwentongshu.com.app.presenter;

import android.content.Context;
import android.support.v4.util.ArrayMap;

import java.util.Map;

import tongwentongshu.com.app.bean.MyShareBean;
import tongwentongshu.com.app.contract.MyShareContract;
import tongwentongshu.com.app.db.Cache;
import tongwentongshu.com.app.dialog.AlertUtils;
import tongwentongshu.com.app.network.ResponseSubscriber;
import tongwentongshu.com.app.update.UpdateFractory;

/**
 * Created by XiongBin on 2017/7/18.
 */

public class MySharePresenter implements MyShareContract.Presenter {
    MyShareContract.View myShareView;
    private Map<String, String> map;
    public MySharePresenter(MyShareContract.View myShareView) {
        this.myShareView = myShareView;
    }

    @Override
    public void getMyShare(Context mContext) {
        AlertUtils.showLoding(mContext);
        map = new ArrayMap<>();
        map.put("token", Cache.getToken());
        map.put("pagesize", "50");

        UpdateFractory.getBuild()
                .name("MyShareCall")
                .map(map)
                .build()
                .execute(new ResponseSubscriber<MyShareBean>() {

                    @Override
                    public void onFailure(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onSuccess(MyShareBean myshare, String msg) {
                        myShareView.onSuccess(myshare);
                    }

                    @Override
                    public void onCompleted() {
                        AlertUtils.disMissLoding();
                        super.onCompleted();
                    }
                });
    }
}
